package com.whiteape.book.ui.adapter;

import android.graphics.Typeface;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.whiteape.book.R;
import com.whiteape.book.model.bo.CategoryDetailBo;
import com.whiteape.book.model.type.HomePageLayoutType;
import com.whiteape.book.model.zssq.section.HomepageSection;
import com.whiteape.book.utils.HomepageLayoutTypeConverter;

import java.util.List;


public class HomepageChildAdapter extends BaseMultiItemQuickAdapter<CategoryDetailBo, BaseViewHolder> {
    public HomepageChildAdapter(List<CategoryDetailBo> data) {
        super(data);
        addItemType(HomePageLayoutType.GRID.ordinal(), R.layout.homepage_item_grid);
        addItemType(HomePageLayoutType.LIST.ordinal(), R.layout.homepage_item_list);
        addItemType(HomePageLayoutType.HEAD.ordinal(), R.layout.item_recommend_header);
    }


    @Override
    protected void convert(BaseViewHolder helper, CategoryDetailBo item) {
        int viewType = helper.getItemViewType();
        if (viewType == HomePageLayoutType.GRID.ordinal()) {
            helper.setText(R.id.coll_book_tv_name, item.getTitle());
            Glide.with(mContext)
                    .load(item.getCoverUrl())
                    .placeholder(R.mipmap.no_cover_portrait)
                    .error(R.mipmap.no_cover_portrait)
                    .fitCenter()
                    .into((ImageView)helper.getView(R.id.coll_book_iv_cover));
            helper.addOnClickListener(R.id.homepage_book_detail);

        } else if (viewType == HomePageLayoutType.LIST.ordinal()) {
            Glide.with(mContext)
                    .load(item.getCoverUrl())
                    .placeholder(R.mipmap.no_cover_portrait)
                    .error(R.mipmap.no_cover_portrait)
                    .fitCenter()
                    .into((ImageView)helper.getView(R.id.homepage_info_iv_cover));
            helper.setText(R.id.homepage_info_tv_title, item.getTitle());
            helper.setText(R.id.homepage_info_tv_desc, item.getDesc());
            helper.addOnClickListener(R.id.homepage_book_detail);

        } else if (viewType == HomePageLayoutType.HEAD.ordinal()) {
            helper.setText(R.id.tv_recommend_header_title, item.getCategoryBean().getCategoryName());
            helper.addOnClickListener(R.id.tv_recommend_header_more);
            TextView tvDetailList = helper.getView(R.id.tv_recommend_header_title);
            tvDetailList.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
            tvDetailList.getPaint().setFakeBoldText(true);
        }
    }

}
